<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        #format {
            word-break: break-all;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
    </style>
</head>
<body style="background-color: #666;color: #fff;presentation-level: increment;">
<pre id="format"></pre>
<script type="text/javascript">
    let sock, tick, format = document.getElementById('format');

    console.log(new Date().getTime());
    console.log(Date.parse(new Date()));

    function message(message) {
        let div = document.createElement('div');
        div.innerHTML = message.data;
        div.style.cssText = 'padding:5px 10px;background-color:#222;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;word-break: break-all;word-wrap: break-word;';
        div.style.marginBottom = '10px';
        let count = format.getElementsByTagName('div');

        format.insertBefore(div, count[0]);
    }

    function close(even) {
        setTimeout(function () {
            connect();
            sock.onmessage = message;
            sock.onclose = close;
        }, 3000);
        console.log(even, 'onClose')
    }

    function connect() {
        sock = new WebSocket('ws://47.92.194.207:9530?token=de5cfdf897-e2f-65de-b5686aca2-5575fe&access_token='+encodeURIComponent('ZgHcxCzVuV7kKQsf/j07N5J7BnC1VE5sS32/07utoibiLHLBXLa9htX3LMsik2DY2w0n+MUibQayG0diedcD8g==')+'&iv=iv340f0be2Fx0VvP');
        sock.onopen = function () {
            if (tick) {
                clearInterval(tick)
            }
            tick = setInterval(function () {
                sock.send(JSON.stringify({'route': 'getUserPosition', 'tick': new Date().getTime()}));
            }, 3000)
        }
    }

    connect();
    sock.onmessage = message;
    sock.onclose = close;
</script>
</body>
</html>
